class Solution {
    public String convert(String s, int numRows) {
        if (numRows == 1) return s;
        char[] ss = s.toCharArray();
        int len = ss.length;
        StringBuilder stringBuilder = new StringBuilder();
        int d = 2 * numRows - 2;//公差
        for (int i = 0; i < numRows; i++) {
            int k = i;
            if (k == 0) {
                while (k < len) {
                    stringBuilder.append(ss[k]);
                    k += d;
                }
            } else if (k == numRows - 1) {
                while (k < len) {
                    stringBuilder.append(ss[k]);
                    k += d;
                }
            } else {
                int k2 = d - k;
                while (k < len || k2 < len) {
                    if (k < len) stringBuilder.append(ss[k]);
                    if (k2 < len) stringBuilder.append(ss[k2]);
                    k += d;
                    k2 += d;
                }
            }
        }
        return stringBuilder.toString();
    }
}